﻿using Coldairarrow.Business.Base_Test;
using Coldairarrow.Entity.Base_Test;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base_Test
{
    [Route("/Base_Test/[controller]/[action]")]
    public class testtableController : BaseApiController
    {
        #region DI

        public testtableController(ItesttableBusiness testtableBus)
        {
            _testtableBus = testtableBus;
        }

        ItesttableBusiness _testtableBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<testtable>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _testtableBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<testtable> GetTheData(IdInputDTO input)
        {
            return await _testtableBus.GetTheDataAsync(input.id);
        }

        [HttpPost]
        public string GetUrl()
        {
            string temp = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic9.nipic.com%2F20100914%2F2531170_171928949919_2.jpg&refer=http%3A%2F%2Fpic9.nipic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1641526539&t=90ceffd51282cb2d4987aae4e8d34a74";
            return  temp;

        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(testtable data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _testtableBus.AddDataAsync(data);
            }
            else
            {
                await _testtableBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _testtableBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}